

<?php
if ($this->code == "0"){
    echo "<legend>";
    echo $this->msg;
    echo "</legend>";
}else echo $this->msg;

if (is_null($this->code)){
?>

<legend>Pembelian Voucher Seluler/PLN</legend>
<div class="row clearfix">
<div class="col-md-8 column">
    <form  method="post" id="frm" name="frm">
                <!-- Member form -->

                
                <?php //echo $this->today; ?>
                
                <h4>Data Pembelian</h4>
                
                <!-- fromAcc input-->
                <div class="form-group">
                    <label class="control-label">Dari Rekening</label>
                    
                        <select id="fromAcc" name="fromAcc" class="form-control">
                            <?php
                            
                           foreach ($this->accountList as $oAcc) {
                                    echo "<option value='".$oAcc['bank_account_no']."'>". $oAcc['bank_name'] .' '. $oAcc['bank_account_no'] ." (". $oAcc['account_name'] .")</option>";
                           }
                           ?>
                        </select>
                </div>
                
                <div class="form-group">
                    
                    <select id="slOperator" name="slOperator" class="form-control" required>
                           <option value=''>== Pilih Operator ==</option>
                           <?php
                           foreach ($this->op as $ops){
                           
                           echo "<option value='".$ops['pulsa_operator']."'>". $ops['pulsa_operator'] ."</option>";
                           
                           }
                           ?>
                        </select>
                </div>

                <!-- voucherCode input-->
                <div class="form-group">
                        <select id="voucherCode" name="voucherCode" class="form-control" required>
                           <option value=''>== Pilih Voucher ==</option>                           
                        </select>
                </div>

                <!-- no_celluler input-->
                <div class="form-group">
                    <input id="no_celluler" name="no_celluler" type="text" placeholder="Nomor Seluler/PLN"
                    class="form-control" required>
                    <p class="help-block">Pastikan Nomor Seluler/PLN yang Anda masukan benar. Transaksi yang telah dikirim tidak dapat dibatalkan.</p>

                </div>

                <!-- remark input-->
                <div class="form-group">
                        <textarea id="remark" name="remark" type="text" placeholder="Catatan"
                        class="form-control"></textarea>
                </div>

                <!-- submit btn-->
                <div class="form-group">
                    <label class="control-label"></label>
                    <div class="controls">
                        <button class="btn btn-default" type="submit" id="btnSubmit" name="btnSubmit">
                        Submit</button> <div id="div_result"></div>
                        <p class="help-block"></p>
                    </div>
                </div>

        </form>
</div>
</div>
        <script>

          $("select#slOperator").change(function(){
             var op = $("#slOperator").val();
             var options = '';
             options += '<option value="">== Loading Voucher ==</option>';
             $("select#voucherCode").html(options);
             $("select#voucherCode").attr('disabled','disabled');

             $.getJSON("<?php echo $this->baseUrl() ?>/jsondata/vouchercode",{slOperator: op, ajax: 'true'}, function(j){
                  options = '';
                  options += '<option value="">== Pilih Voucher ==</option>';
                  for (var i = 0; i < j.length; i++) {
                    options += '<option value="' + j[i].pulsa_code + '">' + j[i].pulsa_desc + '</option>';
                  }
                  $("select#voucherCode").removeAttr('disabled');
                  $("select#voucherCode").html(options);
            })
          });
            

        /* Attach a submit handler to the form */
        $("#frm").submit(function(event) {

            /* Stop form from submitting normally */
            event.preventDefault();

            /* Clear result div*/
            $("#div_result").html('');
            $("#btnSubmit").html('Memproses...');
            $("#btnSubmit").attr('disabled','disabled');

            /* Get some values from elements on the page: */
            var values = $(this).serialize();

            var msg = [];
            
            /* Send the data using post and put the results in a div */

            $.ajax({
                url: "<?php echo $this->baseUrl() ?>/purchase/cellphonebuy/",
                type: "post",
                data: values,
                success: function(response, opts){
                    //var cekSess = response.toUpperCase().search("SESSION TIMEOUT");

                    //if (cekSess < 0){
                        var cekStatus = response.toUpperCase().search("ERROR");

                        if (cekStatus < 0){
                            $("#div_content").html(response);
                            location.href='#div_content';
                        }else{

                            var resp = response.replace('ERROR', '');

                            msg.push('<span>'+resp+'</span>');
                            $.messager.alert('Info', msg.join('<br/>'));

                            //$("#div_result").html(resp);
                            $("#btnSubmit").removeAttr('disabled');
                            $("#btnSubmit").html('Submit');
                        }
                    /*}else{
                        location.href='<?php echo $this->baseUrl() ?>/index/login/msg/Session Timeout silahkan login kembali !';
                    }*/
                },
                error:function(response, opts){
                    //alert("failure");
                    msg.push('<span>'+response+'</span>');
                    $.messager.alert('Info', msg.join('<br/>'));

                    $("#btnSubmit").removeAttr('disabled');
                    $("#btnSubmit").html('Submit');
                }
            });

        });

        </script>

        <?php } ?>
    